import 'package:lai_zhan/common/config/ExportConfig.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:lai_zhan/widget/CourseItem.dart';
class CourseListPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _CourseListPageState();
  }
}

class _CourseListPageState extends State<CourseListPage> {

  RefreshController _controller;
  int itemcount = 10;

  LoadConfig _footerConfig = new LoadConfig(autoLoad: true,bottomWhenBuild: true,triggerDistance: 10.0);

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    _controller = new RefreshController();
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return BaseScaffold(
      title: '团体课',
      back: () {
        NavigatorUtil.goBack(context);
      },
      backgroundColor: Color(AppColors.primaryColor),
      titleColor: Color(AppColors.white),
      actions: <Widget>[
        new IconButton(
            icon: Icon(
              Icons.search,
              color: Color(AppColors.white),
              size: 25,
            ),
            onPressed: () {
              //搜索
            })
      ],
      body: new SmartRefresher(
          enablePullDown: false,
          enablePullUp: true,
          footerBuilder: _footerCreate,
          footerConfig: _footerConfig,
          controller: _controller,
          onRefresh: (up){
            new Future.delayed(new Duration(seconds: 3),(){
              setState(() {itemcount=15;});
              _controller.sendBack(false, RefreshStatus.idle);
            });
          },
          child: new ListView.builder(
            itemBuilder: (context, index){
              return new CourseItem(onClick: (){
                //跳转到课程详情页
                NavigatorUtil.goCoursePage(context);
              },);
            },
            itemCount: itemcount,
          )),
    );
  }

  Widget _footerCreate(BuildContext context, int mode) {
    return new ClassicIndicator(
      mode: mode,
      refreshingText: '加载更多',
      idleIcon: const Icon(Icons.arrow_upward),
      idleText: '加载完成',
    );
  }
}
